package com.petAdoption.manager.util;


import lombok.Data;
import org.springframework.stereotype.Component;

import java.io.Serializable;

@Component
@Data
public class Result<T> implements Serializable {
    private int code;
    private String message;
    private T data;

    public Result() {
    }

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result success() {
        Result result = new Result();
        result.setCode(0);
        result.setMessage(null);
        result.setData(null);
        return result;
    }

    public Result success(String message) {
        Result result = new Result();
        result.setCode(0);
        result.setMessage(message);
        result.setData(null);
        return result;
    }

    public Result success(T data) {
        Result result = new Result();
        result.setCode(0);
        result.setMessage(null);
        result.setData(data);
        return result;
    }

    public Result success(String message, T data) {
        Result result = new Result();
        result.setCode(0);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public Result success(Integer code, String message, T data) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }


    public Result fail() {
        Result result = new Result();
        result.setCode(1);
        result.setMessage(null);
        result.setData(null);
        return result;
    }

    public Result fail(String message) {
        Result result = new Result();
        result.setCode(1);
        result.setMessage(message);
        result.setData(null);
        return result;
    }

    public Result fail(T data) {
        Result result = new Result();
        result.setCode(1);
        result.setMessage(null);
        result.setData(data);
        return result;
    }

    public Result fail(String message, T data) {
        Result result = new Result();
        result.setCode(1);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public Result fail(Integer code, String message, T data) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public Result error() {
        Result result = new Result();
        result.setCode(1);
        result.setMessage(null);
        result.setData(null);
        return result;
    }

    public Result error(String message) {
        Result result = new Result();
        result.setCode(1);
        result.setMessage(message);
        result.setData(null);
        return result;
    }

    public Result error(String message, T data) {
        Result result = new Result();
        result.setCode(1);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public Result error(Integer code, String message, T data) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

}